/*=====================================================
Critical Links
Auto Configuration Server

Authors:
	Rui Eduardo Gouveia Gil - r-gil@critical-links.com

Date: 2011
Version 0.1
=======================================================*/
ACSGui = {};

Ext.onReady(function(){
    Ext.QuickTips.init();

    var tpl = Ext.Template.from('preview-tpl', {
        compiled:true,
        getBody : function(v, all){
            return Ext.util.Format.stripScripts(v || all.description);
        }
    });
    
    ACSGui.getTemplate = function(){
        return tpl;
    }

    var tree = new ACSTree();
    var mainPanel = new ACSMainPanel();

    tree.on('nodeselect', function(obj){
        mainPanel.load(obj);
    });

    tree.on('nodereload', function(obj){
        mainPanel.reload(obj);
    });

    tree.on('noderemove', function(obj){
        mainPanel.unload(obj);
    });

    mainPanel.on('refreshtree', function(obj){
    	tree.refresh();
    });

    var viewport = new Ext.Viewport({
        layout:'border',
        items:[
            new Ext.BoxComponent({ // raw element
                region:'north',
                el: 'header',
                height:32
            }),
            tree,
            mainPanel
         ]
    });

    Ext.get('header').on('click', function() {
        viewport.focus();
    });
    
    tree.focus();
});
